package com.ruoyi.web.controller.proreportcontactsheet;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.ProRepairEngineers;
import com.ruoyi.domain.ProReportContactSheet;
import com.ruoyi.service.IProReportContactSheetService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * 维保报告书联系单Controller
 * 
 * @author ruoyi
 * @date 2020-07-04
 */
@Controller
@RequestMapping("/ruoyi/sheet")
public class ProReportContactSheetController extends BaseController
{
    private String prefix = "ruoyi/sheet";

    @Autowired
    private IProReportContactSheetService proReportContactSheetService;

    @RequiresPermissions("ruoyi:sheet:view")
    @GetMapping("/sheet/{mtId}")
    public String sheet(@PathVariable("mtId") Long mtId,ModelMap mmap)
    {
        mmap.put("mtId",mtId);
        return prefix + "/sheet";
    }

    /**
     * 按Id查询维保项目合同列表
     */
    @RequiresPermissions("ruoyi:contact:list")
    @PostMapping("/lists/{mtId}")
    @ResponseBody
    public TableDataInfo lists(@PathVariable("mtId") Long mtId)
    {
        startPage();
        List<ProReportContactSheet> lists = proReportContactSheetService.selectProReportContactSheetListById(mtId);
        return getDataTable(lists);
    }

    /**
     * 查询维保报告书联系单列表
     */
    @RequiresPermissions("ruoyi:sheet:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProReportContactSheet proReportContactSheet)
    {
        startPage();
        List<ProReportContactSheet> list = proReportContactSheetService.selectProReportContactSheetList(proReportContactSheet);
//        list.removeIf(proReportContactSheet1 -> proReportContactSheet1.getmMreport()==null);
//        list.removeIf(proReportContactSheet1 -> proReportContactSheet1.getmMcontactSheet()==null);
        return getDataTable(list);
    }

    /**
     * 导出维保报告书联系单列表
     */
    @RequiresPermissions("ruoyi:sheet:export")
    @Log(title = "维保报告书联系单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProReportContactSheet proReportContactSheet)
    {
        List<ProReportContactSheet> list = proReportContactSheetService.selectProReportContactSheetList(proReportContactSheet);
        ExcelUtil<ProReportContactSheet> util = new ExcelUtil<ProReportContactSheet>(ProReportContactSheet.class);
        return util.exportExcel(list, "sheet");
    }

    /**
     * 新增维保报告书联系单
     */
    @GetMapping("/add/{mtId}")
    public String add(@PathVariable("mtId") Long mtId,ModelMap mmap)
    {
        mmap.put("mtId",mtId);
        return prefix + "/add";
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestParam("file") MultipartFile file,
                              @RequestParam("file1") MultipartFile file1,
                              @RequestParam("file2") MultipartFile file2,
                              @RequestParam("file3") MultipartFile file3,
                              ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String fileName1 = FileUploadUtils.upload(filePath, file1);
        String fileName2 = FileUploadUtils.upload(filePath, file2);
        String fileName3= FileUploadUtils.upload(filePath, file3);
        //proReportContactSheet.setmTime(new Date());
        proReportContactSheet.setmMreport(fileName);
        proReportContactSheet.setmMcontactSheet(fileName1);
        proReportContactSheet.setmMforPayment(fileName2);
        proReportContactSheet.setmCheckProblem(fileName3);
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }


    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addone")
    @ResponseBody
    public AjaxResult addSaves(@RequestParam("file") MultipartFile file,
//                              @RequestParam("file2") MultipartFile file2,
//                              @RequestParam("file3") MultipartFile file3,
                              ProReportContactSheet proReportContactSheet)throws IOException
    {

        String filePath = Global.getUploadPath();
        String fileName = FileUploadUtils.upload(filePath, file);
        proReportContactSheet.setmMreport(fileName);
        //proReportContactSheet.setmTime(new Date());
        // 上传文件路径
//        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
//        String fileName = FileUploadUtils.upload(filePath, file);
//        String fileName1 = FileUploadUtils.upload(filePath, file1);
//        String fileName2 = FileUploadUtils.upload(filePath, file2);
//        String fileName3= FileUploadUtils.upload(filePath, file3);
//        proReportContactSheet.setmTime(new Date());
//        proReportContactSheet.setmMreport(fileName);
//        proReportContactSheet.setmMcontactSheet(fileName1);
//        proReportContactSheet.setmMforPayment(fileName2);
//        proReportContactSheet.setmCheckProblem(fileName3);

        /*if(proReportContactSheet1.getmMreport()!=null){
            proReportContactSheet.getmMreport();
            proReportContactSheet.setmMreport(fileName);
        }else if(proReportContactSheet1.getmMcontactSheet()!=null){
            proReportContactSheet.getmMcontactSheet();
            proReportContactSheet.setmMcontactSheet(fileName1);
        }else{
            return toAjax(0);
        }*/

        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addtwo")
    @ResponseBody
    public AjaxResult addSavess(@RequestParam("file1") MultipartFile file1, ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName1 = FileUploadUtils.upload(filePath, file1);
        proReportContactSheet.setmMcontactSheet(fileName1);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addthree")
    @ResponseBody
    public AjaxResult addSavethree(@RequestParam("file2") MultipartFile file2, ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName2 = FileUploadUtils.upload(filePath, file2);
        proReportContactSheet.setmMforPayment(fileName2);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addfour")
    @ResponseBody
    public AjaxResult addSavefour(@RequestParam("file3") MultipartFile file3, ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName3 = FileUploadUtils.upload(filePath, file3);
        proReportContactSheet.setmCheckProblem(fileName3);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addfive")
    @ResponseBody
    public AjaxResult addSavefive(@RequestParam("file") MultipartFile file,
                                  @RequestParam("file1") MultipartFile file1,
                                  ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String fileName1 = FileUploadUtils.upload(filePath, file1);
        proReportContactSheet.setmMreport(fileName);
        proReportContactSheet.setmMcontactSheet(fileName1);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addsix")
    @ResponseBody
    public AjaxResult addSavesix(@RequestParam("file") MultipartFile file,
                                  @RequestParam("file2") MultipartFile file2,
                                  ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String fileName2 = FileUploadUtils.upload(filePath, file2);
        proReportContactSheet.setmMreport(fileName);
        proReportContactSheet.setmMforPayment(fileName2);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }


    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addseven")
    @ResponseBody
    public AjaxResult addSaveseven(@RequestParam("file") MultipartFile file,
                                 @RequestParam("file3") MultipartFile file3,
                                 ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String fileName3 = FileUploadUtils.upload(filePath, file3);
        proReportContactSheet.setmMreport(fileName);
        proReportContactSheet.setmCheckProblem(fileName3);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addeight")
    @ResponseBody
    public AjaxResult addSaveeight(@RequestParam("file1") MultipartFile file1,
                                   @RequestParam("file2") MultipartFile file2,
                                   ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName1 = FileUploadUtils.upload(filePath, file1);
        String fileName2 = FileUploadUtils.upload(filePath, file2);
        proReportContactSheet.setmMcontactSheet(fileName1);
        proReportContactSheet.setmMforPayment(fileName2);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }


    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addnine")
    @ResponseBody
    public AjaxResult addSavenine(@RequestParam("file1") MultipartFile file1,
                                   @RequestParam("file3") MultipartFile file3,
                                   ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName1 = FileUploadUtils.upload(filePath, file1);
        String fileName3 = FileUploadUtils.upload(filePath, file3);
        proReportContactSheet.setmMcontactSheet(fileName1);
        proReportContactSheet.setmCheckProblem(fileName3);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addten")
    @ResponseBody
    public AjaxResult addSaveten(@RequestParam("file2") MultipartFile file2,
                                  @RequestParam("file3") MultipartFile file3,
                                  ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName2 = FileUploadUtils.upload(filePath, file2);
        String fileName3 = FileUploadUtils.upload(filePath, file3);
        proReportContactSheet.setmMforPayment(fileName2);
        proReportContactSheet.setmCheckProblem(fileName3);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addeleven")
    @ResponseBody
    public AjaxResult addSaveeleven(@RequestParam("file") MultipartFile file,
                                    @RequestParam("file1") MultipartFile file1,
                                    @RequestParam("file2") MultipartFile file2,
                                    ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String fileName2 = FileUploadUtils.upload(filePath, file2);
        String fileName1 = FileUploadUtils.upload(filePath, file1);
        proReportContactSheet.setmMforPayment(fileName2);
        proReportContactSheet.setmMcontactSheet(fileName1);
        proReportContactSheet.setmMreport(fileName);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addetwelve")
    @ResponseBody
    public AjaxResult addSavetwelve(@RequestParam("file") MultipartFile file,
                                    @RequestParam("file1") MultipartFile file1,
                                    @RequestParam("file3") MultipartFile file3,
                                    ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String fileName3 = FileUploadUtils.upload(filePath, file3);
        String fileName1 = FileUploadUtils.upload(filePath, file1);
        proReportContactSheet.setmCheckProblem(fileName3);
        proReportContactSheet.setmMcontactSheet(fileName1);
        proReportContactSheet.setmMreport(fileName);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addethirteen")
    @ResponseBody
    public AjaxResult addSavethirteen(@RequestParam("file") MultipartFile file,
                                    @RequestParam("file2") MultipartFile file2,
                                    @RequestParam("file3") MultipartFile file3,
                                    ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String fileName3 = FileUploadUtils.upload(filePath, file3);
        String fileName2 = FileUploadUtils.upload(filePath, file2);
        proReportContactSheet.setmCheckProblem(fileName3);
        proReportContactSheet.setmMforPayment(fileName2);
        proReportContactSheet.setmMreport(fileName);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }

    /**
     * 新增保存维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:add")
    @Log(title = "维保报告书联系单", businessType = BusinessType.INSERT)
    @PostMapping("/addfourteen")
    @ResponseBody
    public AjaxResult addSavefourteen(@RequestParam("file1") MultipartFile file1,
                                      @RequestParam("file2") MultipartFile file2,
                                      @RequestParam("file3") MultipartFile file3,
                                      ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName1 = FileUploadUtils.upload(filePath, file1);
        String fileName3 = FileUploadUtils.upload(filePath, file3);
        String fileName2 = FileUploadUtils.upload(filePath, file2);
        proReportContactSheet.setmCheckProblem(fileName3);
        proReportContactSheet.setmMforPayment(fileName2);
        proReportContactSheet.setmMcontactSheet(fileName1);
        //proReportContactSheet.setmTime(new Date());
        return toAjax(proReportContactSheetService.insertProReportContactSheet(proReportContactSheet));
    }


    /**
     * 修改维保报告书联系单 维保报告书修改页面
     */
    @GetMapping("/edit/{mId}")
    public String edit(@PathVariable("mId") Long mId, ModelMap mmap)
    {
        ProReportContactSheet proReportContactSheet = proReportContactSheetService.selectProReportContactSheetById(mId);
        mmap.put("proReportContactSheet", proReportContactSheet);
        return prefix + "/edit";
    }

    /**
     * 修改保存维保报告书联系单 维保报告书修改页面
     */
    @RequiresPermissions("ruoyi:sheet:edit")
    @Log(title = "维保报告书联系单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestParam("file") MultipartFile file,
                               ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        //String fileName = FileUploadUtils.upload(filePath, file);
        String fileName = FileUploadUtils.upload(filePath, file);
        proReportContactSheet.setmMreport(fileName);
        return toAjax(proReportContactSheetService.updateProReportContactSheet(proReportContactSheet));
    }


    /**
     * 修改维保报告书联系单 维保联系单修改页面
     */
    @GetMapping("/edits/{mId}")
    public String edits(@PathVariable("mId") Long mId, ModelMap mmap)
    {
        ProReportContactSheet proReportContactSheet = proReportContactSheetService.selectProReportContactSheetById(mId);
        mmap.put("proReportContactSheet", proReportContactSheet);
        return prefix + "/edits";
    }

    /**
     * 修改保存维保报告书联系单 维保联系单修改页面
     */
    @RequiresPermissions("ruoyi:sheet:edits")
    @Log(title = "维保报告书联系单", businessType = BusinessType.UPDATE)
    @PostMapping("/edits")
    @ResponseBody
    public AjaxResult editSaves(@RequestParam("file1") MultipartFile file1,
                               ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        //String fileName = FileUploadUtils.upload(filePath, file);
        String fileName1 = FileUploadUtils.upload(filePath, file1);
        proReportContactSheet.setmMcontactSheet(fileName1);
        return toAjax(proReportContactSheetService.updateProReportContactSheet(proReportContactSheet));
    }

    /**
     * 修改维保报告书联系单 维保费申请支付单修改页面
     */
    @GetMapping("/editss/{mId}")
    public String editss(@PathVariable("mId") Long mId, ModelMap mmap)
    {
        ProReportContactSheet proReportContactSheet = proReportContactSheetService.selectProReportContactSheetById(mId);
        mmap.put("proReportContactSheet", proReportContactSheet);
        return prefix + "/editss";
    }

    /**
     * 修改保存维保报告书联系单 维保费申请支付单修改页面
     */
    @RequiresPermissions("ruoyi:sheet:editss")
    @Log(title = "维保报告书联系单", businessType = BusinessType.UPDATE)
    @PostMapping("/editss")
    @ResponseBody
    public AjaxResult editSavess(@RequestParam("file2") MultipartFile file2,
                                ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        //String fileName = FileUploadUtils.upload(filePath, file);
        String fileName2 = FileUploadUtils.upload(filePath, file2);
        proReportContactSheet.setmMforPayment(fileName2);
        return toAjax(proReportContactSheetService.updateProReportContactSheet(proReportContactSheet));
    }


    /**
     * 修改维保报告书联系单 排查问题联系单修改页面
     */
    @GetMapping("/editsss/{mId}")
    public String editsss(@PathVariable("mId") Long mId, ModelMap mmap)
    {
        ProReportContactSheet proReportContactSheet = proReportContactSheetService.selectProReportContactSheetById(mId);
        mmap.put("proReportContactSheet", proReportContactSheet);
        return prefix + "/editsss";
    }

    /**
     * 修改保存维保报告书联系单 排查问题联系单修改页面
     */
    @RequiresPermissions("ruoyi:sheet:editsss")
    @Log(title = "维保报告书联系单", businessType = BusinessType.UPDATE)
    @PostMapping("/editsss")
    @ResponseBody
    public AjaxResult editSavesss(@RequestParam("file3") MultipartFile file3,
                                 ProReportContactSheet proReportContactSheet)throws IOException
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        //String fileName = FileUploadUtils.upload(filePath, file);
        String fileName3 = FileUploadUtils.upload(filePath, file3);
        proReportContactSheet.setmCheckProblem(fileName3);
        return toAjax(proReportContactSheetService.updateProReportContactSheet(proReportContactSheet));
    }


    /**
     * 删除维保报告书联系单
     */
    @RequiresPermissions("ruoyi:sheet:remove")
    @Log(title = "维保报告书联系单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(proReportContactSheetService.deleteProReportContactSheetByIds(ids));
    }
}
